/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * For testing purpose
 * @author: jin Chen 
 * @date: Oct 13, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.toolkits.selectcontrol;

import edu.psu.geovista.app.pcp.toolkits.table.ConfigureTableModel;

import javax.swing.table.TableColumn;
import java.util.Vector;

public class SimpleListControlPane extends ListControlPane {
    public SimpleListControlPane() {
        this.reset() ;
        this.intiTable() ;
    }
    protected void initButtons() {
        String[] names=new String[]{"Show","Hide","Show all","Hide all","Up","Down","Top","Bottom","Apply"};
        this.addButtons(names);

    }
    protected void reset() {
        String[] items=new String[10];
        for (int i=0;i<items.length ;i++){
            items[i]="item "+i;
        }
        this.setListData(items);
    }

    //1.create tableModel //2. init values
    protected void intiTable() {
        //1. Model
        int initRowCount=0;
        Vector colName=new Vector();
        colName.add("Name");colName.add("NumRec");
        Class[] types = new Class [] {
                 java.lang.String.class, java.lang.Integer.class
        };
        boolean[] editable={false,false,false};
        ConfigureTableModel model=new ConfigureTableModel(colName,initRowCount);
        model.setTypes(types);
        model.setEditables(editable);
        myTable.setModel(model);




    }
    public void setSize() {
         int w=myTable.getSize().width ;
        TableColumn ncol = myTable.getColumnModel().getColumn(0); //.getColumn("Name");
        ncol.setPreferredWidth(w*2/3);
        myTable.repaint();
    }

    protected void actOnButtonClick(String btnName) {
        //"Right","Left","Right all","Left all","Up","Down","Apply"
        if(btnName.equals("Show") ){
            this.moveRight();
        }
        else if(btnName.equals("Hide") ){
            this.moveLeft() ;
        }
        else if(btnName.equals("Up")){
            this.moveUp();

        }
        else if(btnName.equals("Down")){
            this.moveDown() ;
        }
        else if (btnName.equals("Show all")){
            this.moveAllRight() ;
        }
        else if (btnName.equals("Hide all")){
             this.moveAllLeft() ;
        }
        else if (btnName.equals("Top")){
             this.moveTop() ;
             System.out.println("Top");
        }
         else if (btnName.equals("Bottom")){
             this.moveBottom() ;
             System.out.println("Bottom");
        }
         else if (btnName.equals("Apply")){
             this.apply() ;
             System.out.println("Apply");
        }
    }                   
    /*******************************************************************************************************
     *                button actions
     *******************************************************************************************************/
    /**
     * work together with intiTable()
     * @param name
     */
    protected void addRecord(String name) {
        Object[] arow={name, new Integer(1000)};
                this.myTable.addRow(arow);
        //Object[] arow={columnName, new Integer(rowCount) };
    }


}
